package com.dd.ljzapplication.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dd.ljzapplication.R;

import java.util.List;

/**
 * Created by LiJZ on 2016/11/29.
 */

public class TestNewAdapter extends BaseRVAdapter06<String> {


	public TestNewAdapter(List<String> mListData, Context context) {
		super(mListData, context);
	}

	public TestNewAdapter(Context context) {
		super(context);
	}

	@Override
	public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
		((MyHolder) holder).textView.setText(mListData.get(position));
	}


	@Override
	public int getDisplayType(int postion) {
		if (postion % 2 == 0) {
			return 1001;
		} else {
			return 1002;
		}
	}

	@Override
	public RecyclerView.ViewHolder onCreateDisplayHolder(ViewGroup parent, int viewType) {
		View view = mLayoutInflater.inflate(R.layout.item_recycler, parent, false);
		MyHolder holder = new MyHolder(view);
		if (viewType == 1001) {
			holder.itemView.setBackgroundColor(mContext.getResources().getColor(R.color.azure));
		} else if (viewType == 1002) {
			holder.itemView.setBackgroundColor(mContext.getResources().getColor(R.color.teal));
		}
		return holder;
	}

	@Override
	public RecyclerView.ViewHolder onCreateFootHolder(ViewGroup parent, int viewType) {
		View view = mLayoutInflater.inflate(R.layout.item_footview_custom, parent, false);
		RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
		view.setLayoutParams(params);
		CustomFootHolder footHolder = new CustomFootHolder(view);
		return footHolder;
	}

	@Override
	public void onFootViewLoadFinish(RecyclerView.ViewHolder holder, int position) {
		CustomFootHolder customFootHolder = (CustomFootHolder) holder;

		customFootHolder.textView2.setText("加载完成了");
		customFootHolder.textView2.setVisibility(View.VISIBLE);
		customFootHolder.textView1.setVisibility(View.GONE);
	}

	@Override
	public void onFootViewLoading(RecyclerView.ViewHolder holder, int position) {
		CustomFootHolder customFootHolder = (CustomFootHolder) holder;
		customFootHolder.textView1.setText("正在加载中。。。。。。。。");
		customFootHolder.textView2.setVisibility(View.GONE);
	}

	static class MyHolder extends RecyclerView.ViewHolder {

		TextView textView;

		public MyHolder(View itemView) {
			super(itemView);
			textView = (TextView) itemView.findViewById(R.id.tv);
		}
	}

	static class CustomFootHolder extends RecyclerView.ViewHolder {
		TextView textView1;
		TextView textView2;

		public CustomFootHolder(View itemView) {
			super(itemView);
			textView1 = (TextView) itemView.findViewById(R.id.tv1);
			textView2 = (TextView) itemView.findViewById(R.id.tv2);
		}
	}

}
